package com.controller;


import java.util.HashMap;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.utils.UploadUtils;
import com.beans.DataJson;

@Controller
@RequestMapping("upload")
public class UploadController {
	@RequestMapping("image")
	@ResponseBody
    public DataJson uploadImage(@RequestParam(value="file") MultipartFile multipartFile) {
    	String imagePath=UploadUtils.upload(multipartFile);
    	DataJson dataJson=new DataJson();
    	if(imagePath !=null) {
    		dataJson.setCode(1);
    		dataJson.setMsg("上传成功");
    		HashMap<String,String> map=new HashMap<>();
    		map.put("src", imagePath);
    		dataJson.setData(map);
    	}else {
    		dataJson.setCode(0);
    		dataJson.setMsg("对不起，上传失败");
    	}
    	return dataJson;
    }
	@RequestMapping("addImage")
	@ResponseBody
	public String addImage(String goodsImage,String imageDescribe){
		System.out.println("当前图片的访问路径:"+goodsImage);
		System.out.println("当前图片的描述信息:"+imageDescribe);
		return "1";
	}
}
